package conf

import (
	// _ "github.com/jinzhu/gorm/dialects/mysql"
	_ "github.com/jinzhu/gorm/dialects/sqlite"
	"github.com/jinzhu/gorm"
	"pojo/model"
)

var DB *gorm.DB

func init() {
	DB, _ = NewDB()
	DB.AutoMigrate(model.Admin{}, model.News{}, model.User{}, model.Adv{}, model.Category{}, model.Goods{})
	DB.LogMode(true)
}

func NewDB() (*gorm.DB, error) {
	// db, err := gorm.Open("mysql", "root:@tcp(127.0.0.1:3306)/shop?charset=utf8&parseTime=True&loc=Local")
	db, err := gorm.Open("sqlite3", "product.db")

	return db, err
}
